package com.unbank.rest;

import java.util.Date;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.springframework.stereotype.Component;
import com.unbank.entity.News;
import com.unbank.index.IndexClient;

@Component
@Path("/index")
public class IndexService {
	
	/**
	 * 后期需修改为Spring注入方式
	 */
	private IndexClient indexClient;
	

	/**
	 * 2015-4-24 由于暂时尚未实现@Beanparam的方法，后期需修改
	 * @param crawl_id
	 * @param url
	 * @param title
	 * @param content
	 * @param newsDate
	 * @param crawlDate
	 * @param webName
	 * @param webSectionName
	 * @param website_id
	 * @param p_url
	 * @param tagName
	 * @param keyWords
	 * @return
	 */
	@POST
	@Consumes("application/x-www-form-urlencoded")
	@Path("/oper")
	public String opter(
			@FormParam("crawl_id")int crawl_id,
			@FormParam("url")String url,
			@FormParam("title")String title,
			@FormParam("content")String content,
			@FormParam("webName")String webName,
			@FormParam("newsDate")Long newsDate,
			@FormParam("crawlDate")Long crawlDate,
			@FormParam("webSectionName")String webSectionName,
			@FormParam("website_id")int website_id
			,@FormParam("p_url")String p_url
			,@FormParam("tagName")String tagName,
			@FormParam("keyWords")String keyWords
			){
		News news=new News();
		news.setCrawl_id(crawl_id);
		news.setUrl(p_url);
		news.setTitle(title);
		news.setContent(content);
		news.setNewsDate(newsDate);
		news.setCrawlDate(crawlDate);
		news.setWebName(webName);
		news.setWebSectionName(webSectionName);
		news.setWebsite_id(website_id);
		news.setTagName(tagName);
		news.setP_url(p_url);
		news.setTagName(tagName);
		news.setKeyWords(keyWords);
		
		indexClient=new IndexClient();
		
		indexClient.index(news);
		
		return String.valueOf(crawl_id);
	}
	
}
